from Tkinter import *
import pygame.mixer
import os

class SoundPanel(Frame):
    #creat a Frame as a class
    def __init__(self, app, mixer, sound_file):
        Frame.__init__(self,app)

        self.track = mixer.Sound(sound_file)
        self.track_playing = IntVar()
        track_button = Checkbutton(self, variable = self.track_playing, command = self.track_toggle, text = sound_file)
        track_button.pack(side = LEFT)

        self.volume = DoubleVar()
        self.volume.set(self.track.get_volume())
        volume_scale = Scale(self, variable = self.volume, from_ = 0.0, to = 1.0, resolution = 0.1, command = self.change_volume, label = "Volume", orient = HORIZONTAL)
        volume_scale.pack(side = RIGHT)

    def track_toggle(self):
        if self.track_playing.get():
            self.track.play(loops = -1)
        else:
            self.track.stop()

    #attention! change volume with v parameter
    def change_volume(self,v):
        """docstring for change_volume"""
        self.track.set_volume(self.volume.get())

#Creat tht GUI application window
app = Tk()
app.title("Head First Mix")
#let tk deside how to place widgets
#app.geometry('350x200+200+100')
mixer = pygame.mixer
mixer.init()

#ID the track
dirList = os.listdir(".")
for fname in dirList:
    if fname.endswith(".wav"):
        panel = SoundPanel(app, mixer, fname)
        panel.pack()

app.mainloop()
